import SF from "./sf.vue";
import SFItem from "./sf-item/sf-item.vue";
import { defineAsyncComponent } from "vue";
export const SF_COLLECTION = {
  cascader: defineAsyncComponent(() => import("./sf-cascader/sf-cascader.vue")),
  checkbox: defineAsyncComponent(() => import("./sf-checkbox/sf-checkbox.vue")),
  colorPicker: defineAsyncComponent(
    () => import("./sf-color-picker/sf-color-picker.vue")
  ),
  date: defineAsyncComponent(() => import("./sf-date/sf-date.vue")),
  input: defineAsyncComponent(() => import("./sf-input/sf-input.vue")),
  inputNumber: defineAsyncComponent(
    () => import("./sf-input-number/sf-input-number.vue")
  ),
  object: defineAsyncComponent(() => import("./sf-object/sf-object.vue")),
  radio: defineAsyncComponent(() => import("./sf-radio/sf-radio.vue")),
  rate: defineAsyncComponent(() => import("./sf-rate/sf-rate.vue")),
  select: defineAsyncComponent(() => import("./sf-select/sf-select.vue")),
  slider: defineAsyncComponent(() => import("./sf-slider/sf-slider.vue")),
  switch: defineAsyncComponent(() => import("./sf-switch/sf-switch.vue")),
  textarea: defineAsyncComponent(() => import("./sf-textarea/sf-textarea.vue")),
  upload: defineAsyncComponent(() => import("./sf-upload/sf-upload.vue"))
};

const passWordRule = {
  validator: (rule, value, callback) => {
    const REGEXP_PWD =
      /^(?![0-9]+$)(?![a-z]+$)(?![A-Z]+$)(?!([^(0-9a-zA-Z)]|[()])+$)(?!^.*[\u4E00-\u9FA5].*$)([^(0-9a-zA-Z)]|[()]|[a-z]|[A-Z]|[0-9]){6,18}$/;

    if (!callback) {
      return REGEXP_PWD.test(value);
    }
    if (value === "") {
      callback(new Error("请输入密码"));
    } else if (!REGEXP_PWD.test(value)) {
      callback(new Error("密码格式应为6-18位数字、字母、符号的任意两种组合"));
    } else {
      callback();
    }
  },
  trigger: "blur"
};

const getCustomRule = (regex: RegExp, msg: string, trigger = "blur") => {
  return {
    validator: (rule, value, callback) => {
      if (!callback) {
        return regex.test(value);
      }
      if (value === "") {
        callback(new Error("不能为空"));
      } else if (!regex.test(value)) {
        callback(new Error(msg));
      } else {
        callback();
      }
    },
    trigger
  };
};
export { SF, SFItem, passWordRule, getCustomRule };
